package com.cytech.cloudclinic.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cytech.cloudclinic.R;
import com.cytech.cloudclinic.bean.Drug;
import com.cytech.cloudclinic.utils.ConvertUtils;

import java.util.List;

public class BillDrugAdapter extends BaseQuickAdapter<Drug, BaseViewHolder> {
    public BillDrugAdapter(List<Drug> data) {
        super(R.layout.item_bill_drug, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Drug drug) {
        TextView tvGroup = baseViewHolder.getView(R.id.tv_prescription_group_tag);
        if(drug.headTitle ==-1){
            tvGroup.setVisibility(View.INVISIBLE);
        }else{
            tvGroup.setVisibility(View.VISIBLE);
            tvGroup.setText(String.valueOf(drug.headTitle));
        }
        baseViewHolder.setText(R.id.item_bill_name,drug.drug_name);
        baseViewHolder.setText(R.id.item_bill_size,drug.count +drug.cont_unit_text);

        drug.practical_price = drug.count *drug.sub_price;
        baseViewHolder.setText(R.id.item_bill_price,String.valueOf(drug.practical_price));

        EditText price = baseViewHolder.getView(R.id.item_bill_price);
        price.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                drug.practical_price = ConvertUtils.toDouble(charSequence.toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }
}
